package com.anolesoft.amljmes.fortyone.service.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import com.anolesoft.amljmes.fortyone.entity.BasRclMachines;

import cn.hutool.core.util.StrUtil;

/**
 * 对应表 bas_rcl_machines
 * 
 * @author 陈向前
 *
 */
@Mapper
public interface BasRclMachinesMapper {
	/**
	 * 根据设备编号和名称模糊查询下拉选
	 * 
	 * @param keyWord
	 * @param facCode
	 * @return
	 */
	@SelectProvider(type = SQLBuilder.class, method = "queryBasRclMachinesForSelectSQL")
	List<BasRclMachines> queryBasRclMachinesForSelect(@Param("keyWord") String keyWord,
			@Param("factoryId") String factoryId);

	class SQLBuilder {
		public static String queryBasRclMachinesForSelectSQL(@Param("keyWord") String keyWord,
				@Param("factoryId") String factoryId) {
			return new SQL() {
				{
					SELECT("*");
					FROM("bas_rcl_machines");
					WHERE("factory_id = #{factoryId}");
					if(!StrUtil.isEmptyOrUndefined(keyWord)) {
						WHERE("instr(upper(machinescode||machinesname), upper(trim(#{keyWord}))) > 0");
					}
					ORDER_BY("machinescode");
				}
			}.toString();
		}
	}
}
